package com.share.design.observer.demo01;

import java.util.ArrayList;
import java.util.List;

/**
 * 发布者
 * @author caifan
 * @since 2022/11/4
 */
public class MessagePublisher implements Subject {

    private List<MessageObserver> observers = new ArrayList<>();

    @Override
    public void attach(MessageObserver o) {
        observers.add(o);
    }

    @Override
    public void detach(MessageObserver o) {
        observers.remove(o);
    }

    @Override
    public void notifyUpdate(Message m) {
        observers.forEach(x->x.update(m));
    }

}
